package com.authine.cloudpivot.ext.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import com.authine.cloudpivot.ext.service.IZzdWorkApiService;
import com.authine.cloudpivot.ext.service.base.ZzdBaseServiceImpl;

/**
 * 浙政钉待办接口
 * 
 * @author quyw
 * @date 2021/06/24
 */
@Service
public class ZzdWorkApiServiceImpl extends ZzdBaseServiceImpl implements IZzdWorkApiService {

    private static final Logger log = LoggerFactory.getLogger(ZzdWorkApiServiceImpl.class);

    @Override
    public String packageCancel(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("packageCancel params is,{}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/tc/openapi/package/cancel.json";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("userId", params.get("userId"));
        postClient.addParameter("packageUuid", params.get("packageUuid"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String packageClose(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("packageClose params is,{}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/tc/openapi/package/close.json";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("userId", params.get("userId"));
        postClient.addParameter("packageUuid", params.get("packageUuid"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String taskCancel(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("taskCancel params is,{}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/tc/openapi/task/cancel.json";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("closePackage", params.get("closePackage"));
        postClient.addParameter("userId", params.get("userId"));
        postClient.addParameter("taskUuid", params.get("taskUuid"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String taskFinish(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("taskFinish params is,{}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/tc/openapi/task/finish.json";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("closePackage", params.get("closePackage"));
        postClient.addParameter("userId", params.get("userId"));
        postClient.addParameter("taskUuid", params.get("taskUuid"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String taskCreate(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("taskCreate params is,{}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/tc/v2/openapi/task/create.json";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("assigneeInfo", params.get("assigneeInfo"));
        postClient.addParameter("subject", params.get("subject"));
        postClient.addParameter("creatorInfo", params.get("creatorInfo"));
        postClient.addParameter("creatorId", params.get("creatorId"));
        postClient.addParameter("tenantId", params.get("tenantId"));
        postClient.addParameter("bizTaskId", params.get("bizTaskId"));
        postClient.addParameter("assigneeId", params.get("assigneeId"));
        postClient.addParameter("mobileUrl", params.get("mobileUrl"));
        postClient.addParameter("url", params.get("url"));
        postClient.addParameter("packageUuid", params.get("packageUuid"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String getDoneList(Map<String, String> params) {
        return null;
    }

    @Override
    public String getList(Map<String, String> params) {
        return null;
    }

    @Override
    public String getTodoList(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("getTodoList params is,{}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/tc/openapi/3rd/task/getTodoList";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("tenantId", tenantId);
        postClient.addParameter("userId", params.get("userId"));
        postClient.addParameter("pageNo", params.get("pageNo"));
        postClient.addParameter("pageSize", params.get("pageSize"));
        // postClient.addParameter("finishEndTime", params.get("finishEndTime"));
        // postClient.addParameter("createStartTime", params.get("createStartTime"));
        // postClient.addParameter("createEndTime", params.get("createEndTime"));
        // postClient.addParameter("appKey", appKey);
        // postClient.addParameter("keyword", params.get("keyword"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

}
